#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
#include<unordered_map>

using namespace std;

int longestSubsequence(vector<int>& arr, int difference) {
    int n = arr.size();
    vector<int> f(n, 1);
    unordered_map<int, int> m;
    m[arr[0]] = 1;
    int res = 1;
    for (int i = 1; i < n; i++)
    {
        m[arr[i]] = m[arr[i] - difference] + 1;
        res = max(res, m[arr[i]]);
    }
    return res;
}